package com.hpeu_01.day0113;

public class StringBufferMethod {
    public static void main(String[] args) {
        //创建StringBuffer对象
        StringBuffer buffer = new StringBuffer();
        //StringBuffer append(xxx)：提供了很多的append()方法，用于进行字符串拼接
        buffer.append("java").append("Mysql").append("HTML");//这种方式叫链式编程
        System.out.println(buffer);
        //StringBuffer delete(int start,int end)：删除指定位置的内容
        buffer.delete(0,4);
        System.out.println(buffer);
        //StringBuffer replace(int start, int end, String str)：把 [start,end)位置替换为str
        buffer.replace(0,5,"oracle");
        System.out.println(buffer);
        //StringBuffer insert(int offset, xxx)：在指定位置插入xxx
        buffer.insert(6,"CSS");
        System.out.println(buffer);
        //StringBuffer reverse()：把当前字符序列逆转
        StringBuffer reverse = buffer.reverse();
        System.out.println(reverse);

        StringBuffer buffer1 = new StringBuffer("helloStringBuffer");
        System.out.println(buffer1.length());//注意获取的是字符串的有效长度
        //public int indexOf(String  str)。返回指定字符串首次出现的索引
        int index = buffer1.indexOf("Str");
        System.out.println(index);
        //public String substring(int start,int end) 做字符串的切割
        System.out.println(buffer1.substring(0,5));
        //public int length() 获取字符串的有效长度
        //public char charAt(int n) 返回指定索引的字符
        char c = buffer1.charAt(1);
        System.out.println(c);

        //public void setCharAt(int n ,char ch) 设置指定索引的字符
        buffer1.setCharAt(1,'o');
        System.out.println(buffer1);

    }
}
